<template>
	<view>
		<image src="../../../static/me/bg1.jpg" mode="" style="position: fixed;top: 0; left: 0;width: 100vw; height: 100vh;"></image>
		<view style="z-index: 100;position: absolute;width: 100vw;padding-left: 5px;">
			<view v-if="userInfo  && userInfo.address" style="color: #8a8a8a;text-align: center;">
				{{ userInfo.address.dorm + userInfo.address.room }}
			</view>
			<!-- 还没有选择寝室 -->
			<view v-else><button type="primary" size="mini" @tap="goToSetAddress()">还没有选择寝室，去选择</button></view>

			<!-- 寝室信息 -->
			<view>
				<view class="list">水票价格 ￥{{ address.waterPrice }}</view>
				<view class="list">房间水桶 {{ address.bucketNum }}</view>
				<view class="list">剩余水票 {{ address.ticketNum }}</view>
				<view class="list">上次换水 {{ address.lastTime }}</view>
				<view class="list">
					<button type="primary" size="mini" :disabled="!userInfo || !userInfo.address" class="save-btn" @tap="goToDormHistory()">寝室送水记录</button>
				</view>
			</view>
			<view class="list">寝室成员</view>
			<view v-for="(item, index) in studentList">
				<view class="list-cell ">
					<image :src="item.wxAvatar" style="width: 90rpx;height: 90rpx;border-radius: 50%;"></image>
					<text style="margin: 10rpx 30rpx;">{{ item.studentName ? item.studentName : '???' }}</text>
					{{ item.studentNo }}
					<text style="text-decoration-line: underline;" @tap="warnRoomate()">有误</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 宿舍详细信息
			studentList: [],
			address: {
				waterPrice: '',
				bucketNum: '',
				ticketNum: '',
				lastTime: ''
			},
			userInfo: null
		};
	},
	onShow() {
		this.userInfo = uni.getStorageSync("userInfo")
		if (this.userInfo && this.userInfo.address) this.address = this.userInfo.address;
		this.getAddressStudents();
	},
	methods: {
		// 获取寝室成员
		getAddressStudents() {
			if (!this.userInfo.addressId) return;
			let that = this;
			that.$request('/address/' + this.userInfo.addressId + '/student', 'get').then(result => {
				that.studentList = result.data;
			});
		},
		// 去选择寝室
		goToSetAddress() {
			uni.navigateTo({
				url: '/pages/me/dormitory/setAddress'
			});
		},
		// 查看寝室送水的历史记录
		goToDormHistory() {
			uni.navigateTo({
				url: '/pages/me/dormitory/addressTaskHistory?addressId=' + this.userInfo.addressId
			});
		},
		warnRoomate() {
			// roomie室友 举报该用户不是自己的室友
			let that = this;
			uni.showModal({
				content: '此人不是您的室友?',
				cancelText: '看错了',
				confirmText: '反馈',
				success: function(e) {
					if (e.confirm) {
						that.$msg('已经提交反馈');
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
.list {
	margin: 10rpx;
	font-size: 40rpx;
}
.list-cell {
	line-height: 80rpx;
	display: flex;
	padding: 0 10rpx;
	justify-content: space-between;
	align-items: center;
	border-top: 1px solid #eeeeee;
	border-bottom: 1px solid #eeeeee;
	margin: 0px 5rpx;
}
</style>
